package ualrcdg.shared.dto;

import java.util.HashMap;

/**
 * Simple implementation of the "rule" object. See CDG XML Specifications: Game Descriptor Files.
 */
public class Rule implements AbstractRule
{
	final private String id;
	final private String name;
	final private String type;
	final private HashMap< String, String > parameters;
	
	/**
	 * Primary constructor
	 *
	 * @param id the id of the Rule object to be created
	 * @param name the name of the Rule object to be created
	 * @param type the type of the Rule object to be created
	 * @param parameters the parameters of the Rule object to be created
	 */
	public Rule( String id, String name, String type, HashMap< String, String > parameters )
	{
		this.id = id;
		this.name = name;
		this.type = type;
		this.parameters = new HashMap< String, String >( );
		
		for( String s : parameters.keySet( ) )
		{
			this.parameters.put( s, parameters.get( s ) );
		}
		
		System.out.println( "Parsed: " + this.toString( ) );
	}
	
	/*
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString( )
	{
		return "Rule [id=" + id + ", name=" + name + ", type=" + type + ", parameters=" + parameters + "]";
	}

	/**
	 * @return the name of this Rule instance
	 */
	public String getName( )
	{
		return name;
	}

	/**
	 * @return the ruleName of this Rule instance
	 */
	public String getType( )
	{
		return type;
	}
	
	/**
	 * @param parameterName the name of the desired parameter value
	 * @return the value of the specified parameter of this Rule instance
	 */
	public String getParameter( String parameterName )
	{
		return parameters.get( parameterName );
	}

	/*
	 * @see ualrcdg.shared.dto.AbstractRule#getId()
	 */
	@Override
	public String getId( )
	{
		return id;
	}
}
